package JackSu.常用类.时间日期类;

import org.junit.Test;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Date;

public class _04jdk8中新增的时间处理方式 {

//偏移量测试
    @Test
    public void testDate(){
        Date date = new Date(2022-1900,7-1,20);
        System.out.println(date);


    }

//LocalTime 、LocalDate、LocalDateTime
    @Test
    public  void test1(){
        //now 获取当前日期时间
        LocalDate localDate = LocalDate.now();
        LocalTime localTime = LocalTime.now();
        LocalDateTime localDateTime = LocalDateTime.now();
        System.out.println(localDate);
        System.out.println(localTime);
        System.out.println(localDateTime);

        //of来指定日期时间
        LocalDateTime of = LocalDateTime.of(2022, 7, 20,10,20);
        System.out.println(of);


        //getXxx
        System.out.println(of.getDayOfMonth());
        System.out.println(of.getDayOfYear());
        System.out.println(of.getDayOfWeek());
        System.out.println(of.getMonthValue());

        //set方法 withDayOfMonth
        LocalDateTime localDateTime1 = of.withMonth(8);
        System.out.println(of.getMonthValue());
        System.out.println(localDateTime1.getMonthValue());

        //加 plus
        localDateTime1=of.plusMonths(2);
        System.out.println(localDateTime1);

        //减 minus
        localDateTime1=of.minusDays(2);
        System.out.println(localDateTime1);


    }

}
